﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="muu_dok", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(MuuDok))]
    public class MuuDokSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMuuDok clazz;
        
        public MuuDokSerializer(IMuuDok clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kood");
            if (clazz.Kood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("nimi");
            if (clazz.Nimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("tyyp");
            if (clazz.Tyyp!=null) {
                Writer.WriteTypeAttribute("http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", "muu_dok_tyyp");
                Writer.WriteString(clazz.Tyyp.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("loa_nr");
            if (clazz.LoaNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LoaNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LoaNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("katkomb");
            if (clazz.Katkomb!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Katkomb))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Katkomb");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("vantud");
            if (clazz.Vantud!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Vantud))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Vantud");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kehtib_kuni");
            if (clazz.KehtibKuni!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KehtibKuni))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KehtibKuni");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("olek");
            if (clazz.Olek!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Olek))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Olek");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "kood")) {
                goto kood;
            }
            else {
                if ((Reader.LocalName == "nimi")) {
                    goto nimi;
                }
                else {
                    if ((Reader.LocalName == "tyyp")) {
                        goto tyyp;
                    }
                    else {
                        if ((Reader.LocalName == "loa_nr")) {
                            goto loa_nr;
                        }
                        else {
                            if ((Reader.LocalName == "katkomb")) {
                                goto katkomb;
                            }
                            else {
                                if ((Reader.LocalName == "vantud")) {
                                    goto vantud;
                                }
                                else {
                                    if ((Reader.LocalName == "kehtib_kuni")) {
                                        goto kehtib_kuni;
                                    }
                                    else {
                                        if ((Reader.LocalName == "olek")) {
                                            goto olek;
                                        }
                                        else {
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        kood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>kood");
            }
            clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kood")).Value;
            goto START;
        nimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>nimi");
            }
            clazz.Nimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimi")).Value;
            goto START;
        tyyp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>tyyp");
            }
            clazz.Tyyp = new global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.MuuDokTyyp(Reader.ReadElementString("tyyp"));
            goto START;
        loa_nr:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>loa_nr");
            }
            clazz.LoaNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("loa_nr")).Value;
            goto START;
        katkomb:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>katkomb");
            }
            clazz.Katkomb = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("katkomb")).Value;
            goto START;
        vantud:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>vantud");
            }
            clazz.Vantud = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("vantud")).Value;
            goto START;
        kehtib_kuni:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>kehtib_kuni");
            }
            clazz.KehtibKuni = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kehtib_kuni")).Value;
            goto START;
        olek:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>muu_dok>olek");
            }
            clazz.Olek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("olek")).Value;
            goto START;
        }
    }
}
